package com.atguigu.dga.util;

import okhttp3.Call;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

import java.io.IOException;

/**
 * @Description: TODO
 * @Author: lay
 * @Date: 2024/7/1 20:32
 */
public class HttpClientUtil {
    private static OkHttpClient httpClient = new OkHttpClient();
    
    public static String get(String url){
        try {
            //创建Request对象
            Request.Builder builder = new Request.Builder();
            Request request = builder.url(url).build();

            //创建Call对象
            Call call = httpClient.newCall(request);
            //发送请求
            Response response = call.execute();
            //从响应中获取结果
            return response.body().string();
        } catch (IOException e) {
            e.printStackTrace();
            throw new RuntimeException("发送请求失败...");
        }
    }

    public static void main(String[] args) {
        String s = HttpClientUtil.get("http://hadoop102:18080/api/v1/applications/application_1682967712307_0029");
        System.out.println("s = " + s);
    }
}
